package com.mobilezu.mobile.pushserver.console.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import com.mobilezu.mobile.pushserver.model.PushData;
import com.mobilezu.mobile.pushserver.service.PushDataService;
import com.mobilezu.mobile.pushserver.service.ServiceManager;
import com.mobilezu.mobile.pushserver.util.Constants;


public class DataController extends MultiActionController {

	private PushDataService pushDataService;

	public DataController() {
		pushDataService = ServiceManager.getPushDataService();
	}

	public ModelAndView list(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		List<PushData> dataList = pushDataService.getPushDatas();

		for (PushData pushData : dataList) {
			pushData.setMessage(Constants.subString(pushData.getMessage(), 30));
			pushData.setUri(Constants.subString(pushData.getUri(), 30));
			pushData.setCreatedDate(pushData.getCreatedDate().substring(5));
			pushData.setUpdatedDate(pushData.getUpdatedDate().substring(5));
		}

		ModelAndView mav = new ModelAndView();
		mav.addObject("dataList", dataList);
		mav.setViewName("data/data_list");
		return mav;
	}

}
